package com.legendframework.core.dao.transaction.pojo;

import com.legendframework.core.dao.Return;
import com.legendframework.core.dao.transaction.enums.TransactionStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * IO事务存储的一些数据
 */
public class IOTransaction<D> {

    /**
     * 事务ID
     * 唯一ID
     */
    private String id;

    /**
     * 事务执行状态
     */
    private TransactionStatus status;

    /**
     * 持久化执行链
     *
     * key：IO文件路径 ，Dao与执行类型
     */
    private Map<String,Return<D,ExecuteType>> persistentExecutionChain;

    public IOTransaction(String id, TransactionStatus status) {
        this.id = id;
        this.status = status;
        persistentExecutionChain = new HashMap<>();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public TransactionStatus getStatus() {
        return status;
    }

    public void setStatus(TransactionStatus status) {
        this.status = status;
    }

    public Map<String, Return<D, ExecuteType>> getPersistentExecutionChain() {
        return persistentExecutionChain;
    }

    public void setPersistentExecutionChain(Map<String, Return<D, ExecuteType>> persistentExecutionChain) {
        this.persistentExecutionChain = persistentExecutionChain;
    }

    /**
     * 执行类型
     */
    public static enum ExecuteType {

        UPDATE,

        DELETE

    }
}
